
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#include <librally.h>

#ifndef _RPOINTD
#define _RPOINTD

typedef struct Session {
	int fd;
	struct sockaddr_in addr;
	struct Request *next;
	struct Request *prev;
} Session;

typedef struct SessionQueue {
	rp_mutex_t mutex;
	Session *head;
	Session *tail;
} SessionQueue;

typedef struct {
	int cfgc;
	KeyValue *cfgv;
	char *logdir;
	Log_Level loglv;
	int num_thread_prestart;
	struct timeval tv_io_timeout;
	struct sockaddr_in addr_hsk;
	struct sockaddr_in addr_io;
} Config;

typedef struct {
	Score *score;					// for communication with Rstatd
	OpCode code;
	int fd_stdin;
	int fd_server_hsk;
	int fd_server_io;
	int fd_client_hsk;
	int fd_client_io;
	struct event_base *evb_server;
	struct event ev_adm;
	rp_mutex_t mutex_code;		// the mutex of code
	rp_mutex_t mutex_hsk;		// for lock among different Rpointd processes
	rp_mutex_t mutex_worker;
	rp_sem_t sem_worker;
	rp_thread_t tid_manager;
	Status *status_worker;
	SessionQueue sq;
} Global;

typedef struct {
	char *bindir;
	char *cfgdir;
} Env;

Config config;
Global global;
Env env;

#endif	// _RPOINTD


